<template>
	<!-- 底部地点选择 -->
	<view class="posiBottom">
		<uni-popup ref="popup" type="center" background-color="#fff" @touchmove.stop.prevent="">
			<view class="posiContent">
				<view class="" v-if="getPosiSuccess">请选择您的地址</view>
				<view class="" v-else>无法获取到位置信息，您可手动选择大厦下单</view>
				<scroll-view class="listContent" scroll-y>
					<view class="listContentItem" v-for="(item, index) in addressList" :key="item.siteId">
						<view class="list" @click="checkThisAddress(item)">{{ item.addressName }}</view>
					</view>
				</scroll-view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		queryAllSiteAddress
	} from "@/request/api.js";
	import util from "@/utils/util.js"
	export default {
		name: "posiBottom",
		data() {
			return {
				posiShow: true, // 显示弹窗
				getPosiSuccess: false, //获取定位是否成功
				// 地址列表
				addressList: []
			};
		},
		mounted() {
			// this.queryAllSiteAddressFn();
		},
		methods: {
			// 显示地址列表
			showPois() {
				this.$refs.popup.open('bottom');
			},
			async queryAllSiteAddressFn() {
				// let datas = util.getStorePage();
				// let addressList = datas['addressList']
				// if (addressList) {
				// 	this.addressList = addressList;
				// 	return;
				// }
				let res = await queryAllSiteAddress({
					method: "GET",
					// data: {},
				})
				this.addressList = res.result.allAddress;
				// util.setStorePage([{
				// 	name: 'addressList',
				// 	data: res.result.allAddress
				// }, ]);
			},
			// 选择地址
			checkThisAddress(item) {
				// 使用json 深拷贝 避免 刷新地址时修改引用地址
				this.$emit("checkThisAddress", JSON.parse(JSON.stringify(item)))
			},
		}
	}
</script>

<style lang="scss">
	.posiBottom {
		/deep/.u-drawer-bottom {
			width: 100% !important;
			padding: 36rpx 20rpx 40rpx 20rpx;
			border-top-left-radius: 40rpx;
			border-top-right-radius: 40rpx;
			min-height: 30vh;
			max-height: 80vh;
			overflow: auto;
		}

		/deep/ {
			.u-drawer__scroll-view {
				max-height: 80vh;
			}
		}

		.posiContent {

			overflow-y: scroll;

			>view {
				&:nth-child(1) {
					font-size: 28rpx;
					color: rgba(0, 0, 0, 0.35);
					// margin-bottom: 14rpx;
					padding: 20rpx 20rpx 0;
				}
			}

			>.listContent {
				margin-top: 10rpx;
				height: 80vh;

				.listContentItem {
					.list {
						border-bottom: 1px solid rgba(0, 0, 0, 0.05);
						font-size: 28rpx;
						// line-height: 40rpx;
						padding: 24rpx 20rpx;
					}

					&:last-child {
						border-bottom: 0;

						.list {
							border: 0;
						}
					}
				}
			}
		}

	}
</style>